package com.example.election;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("redissonElectionService")
public class RedissonElectionServiceImpl implements ElectionService {

    private String lockKey = "Redisson_" + getClass().getName() + "_Lock";

    @Resource
    private RedissonClient redissonClient;

    private RLock rLock;

    @Override
    public void doStart() {
        this.rLock = redissonClient.getLock(lockKey);
        this.rLock.lock();
    }

    @Override
    public void doEnd() {
        this.rLock.unlock();
    }
}
